package Core;

public class Bounds extends Object
{
	public int xMax=Integer.MIN_VALUE;
	public int xMin=Integer.MAX_VALUE;
	public int yMax=Integer.MIN_VALUE;
	public int yMin=Integer.MAX_VALUE;

	public Bounds(){}

	public Bounds(int left, int top, int right, int bottom)
	{
		yMin = top;
		yMax = bottom;
		xMin = left;
		xMax = right;
	}

	public int getHeight()
	{
		return yMax - yMin;
	}

	public int getWidth()
	{
		return xMax - xMin;
	}

	public void set(Bounds other)
	{
		yMin = other.yMin;
		yMax = other.yMax;
		xMin = other.xMin;
		xMax = other.xMax;
	}

	public void set(int left, int top, int right, int bottom)
	{
		yMin = top;
		yMax = bottom;
		xMin = left;
		xMax = right;
	}

	public Bounds shift(int sx, int sy)
	{
		xMax += sx;
		xMin += sx;
		yMin += sy;
		yMax += sy;

		return this;
	}

	public void normalise()
	{
		xMax -= xMin;
		xMin=0;
		yMax -= yMin;
		yMin=0;
	}

	public Bounds merge(Bounds other)
	{
		yMin = Math.min(yMin, other.yMin);
		xMin = Math.min(xMin, other.xMin);
		xMax = Math.max(xMax, other.xMax);
		yMax = Math.max(yMax, other.yMax);
		
		return this;
	}

	public Bounds cut(Bounds other)
	{
		yMin = Math.max(yMin, other.yMin);
		xMin = Math.max(xMin, other.xMin);
		xMax = Math.min(xMax, other.xMax);
		yMax = Math.min(yMax, other.yMax);

		return this;
	}

	public String toString()
	{
		return "(" + xMin + ", " + yMin + ") - (" + xMax + ", " + yMax + ")";
	}
}
